package com.zp.qualitypractice;

import android.app.FragmentTransaction;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.Range;
import android.view.View;
import android.view.ViewGroup;

import com.zp.qualitypractice.Dialog.PopupDialogFragment;
import com.zp.qualitypractice.Dialog.SimpleDialogFragment;
import com.zp.qualitypractice.Utils.ToastUtils;
import com.zp.qualitypractice.Utils.UIUtils;

/**
 * Created by izp on 2017/4/21.
 */

public class DemoActivity extends AppCompatActivity implements View.OnClickListener {
    SimpleDialogFragment simpleDialogFragment;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);
        ConstraintLayout viewGroup = (ConstraintLayout) findViewById(R.id.rootView);
        findViewById(R.id.button5).setOnClickListener(this);
        findViewById(R.id.button6).setOnClickListener(this);
        findViewById(R.id.button7).setOnClickListener(this);
        findViewById(R.id.button5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
//        for (int i;new Range(0,10)){
//
//        }
        outer:
        for (int i=0;i<100;i++){
            inner:
            for (int j=0;j<100;j++){
                if (Math.random()*10==5){
                    break outer;
                }else if (Math.random()*10==8){
                    break inner;
                }else if (Math.random()*10==9){
                    continue inner;
                }else if (Math.random()*10==5){
                    continue outer;
                }
            }
        }

        // 标准动画
        // fragmentTransaction
        // .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        // fragmentTransaction
        // .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

        // fragmentTransaction
        // .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);

        // 自定义动画

        // API LEVEL 11
//        fragmentTransaction.setCustomAnimations(
//                R.animator.fragment_slide_left_enter,
//                R.animator.fragment_slide_right_exit);
//
//        // API LEVEL 13
//        // fragmentTransaction.setCustomAnimations(
//        // R.animator.fragment_slide_left_enter,
//        // R.animator.fragment_slide_left_exit,
//        // R.animator.fragment_slide_right_enter,
//        // R.animator.fragment_slide_right_exit);
//
//        fragmentTransaction.add(R.id.container, mTextFragmentOne);
//
//        // 加入到BackStack中
//        fragmentTransaction.addToBackStack(null);
//        fragmentTransaction.commit();

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button5:
                PopupDialogFragment.getInstant(UIUtils.dpToPx(500)).show(getFragmentManager(),PopupDialogFragment.class.getSimpleName());
                break;
            case R.id.button6:

//                FragmentTransaction fragmentTransaction;
//
//                fragmentTransaction = getFragmentManager().beginTransaction();
//                fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
//                simpleDialogFragment.show(fragmentTransaction, SimpleDialogFragment.class.getSimpleName());
//                fragmentTransaction.show(simpleDialogFragment).commit();
                simpleDialogFragment = (SimpleDialogFragment) getFragmentManager().findFragmentByTag(SimpleDialogFragment.class.getSimpleName());
                if (null==simpleDialogFragment){
                    simpleDialogFragment = new SimpleDialogFragment();
                }
                simpleDialogFragment.setBeforeEvent(new SimpleDialogFragment.BeforeShow() {
                    @Override
                    public void doBefore() {

                    }
                }).setAfterEvent(new SimpleDialogFragment.AfterShow() {
                    @Override
                    public void doAfter() {
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                simpleDialogFragment.dismiss();
                                ToastUtils.shortToast(DemoActivity.this,"对话框之后！");
                            }
                        },1000);

                    }
                }).show(getFragmentManager(),SimpleDialogFragment.class.getSimpleName(),FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                break;
        }
    }
}
